import JSEncrypt from 'jsencrypt'
export default {
    methods: {
        async encrypt(password) {
            let publicKey = localStorage.getItem('pubKey');
            if (!publicKey) {
                const res = await this.$axios.get('/api/getPubKey');
                if (res.data.status !== 0) {
                    throw new Error(res.data.msg)
                } else {
                    publicKey = res.data.msg;
                    localStorage.setItem('pubKey', publicKey);
                }
            }
            const encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            return encrypt.encrypt(password);
        }
    }
}